package org.hazelnuts.dao.impl;

import org.hazelnuts.accessor.OracleJdbcAccessor;
import org.hazelnuts.dao.UserRepository;
import org.hazelnuts.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("userRepository")
public class UserRepositoryImpl implements UserRepository {

    @Autowired
    private OracleJdbcAccessor oracleJdbcAccessor;

    @Override
    public int insert(User user) {
        return 0;
    }

    @Override
    public int insert(User user, String tableName) {
        //String sqlString = "INSERT INTO T_TRAVEL_CHUSAI (CMTID, CMTSCORE, CMTTEXT) VALUES(?, ?, ?)";
        //return oracleJdbcAccessor.create(sqlString, user.getId(), user.getAge(), user.getName());
        String sqlString = "INSERT INTO " + tableName.toUpperCase() + " (CMTID, CMTTEXT) VALUES(?, ?)";
        return oracleJdbcAccessor.create(sqlString, user.getId(), user.getName());
    }

    @Override
    public int update(User user) {
        return 0;
    }

    @Override
    public int delete(int id) {
        return 0;
    }

    @Override
    public User findById(int id) {
        return null;
    }

    @Override
    public int testSql() {
        return oracleJdbcAccessor.query();
    }
}